from time import sleep
from selenium import webdriver
import os

# 实例化一个ChromeOptions类的对象
options = webdriver.ChromeOptions()
# 设置打开浏览器时的参数
#   profile.default_content_settings.popups:0 --> 设置为禁止弹出下载窗口
#   download.default_directory:"路径" --> 设置文件下载的路径（不用浏览器默认的）;可以用os.getcwd来获取当前路径
prefs = {
    "profile.default_content_settings.popups": 0,
    "download.default_directory": os.getcwd()
}
options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(options=options)
driver.implicitly_wait(10)
driver.maximize_window()
driver.get("https://pypi.org/project/selenium/#files")
sleep(2)
driver.find_element("xpath", '//*[@id="files"]/div/div[2]/a[1]').click()
